package qz_rpt

class StepStatusAnalysisController {

    def commonDataService
    def dynamicQueryService
    def index(Integer max) {
        def cellList = org.kdx.DataUtils.getCellList()
        def pageSizeList = org.kdx.DataUtils.getPageSizeList()

        [totalCount: 5, pageSize: 20, pageCurrent: 1, orderField: 'id', orderDirection: 'asc', pageSizeList: pageSizeList, cellList: cellList]
    }

    def stepStatusAnalysis(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def stepStatusAnalysisSum=[]
        def tableHeadList=[]
        def stepStatusAnalysis=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0

        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysis'
            stepStatusAnalysis = dynamicQueryService.queryForList(params)
            tableHeadList =  []
            if(stepStatusAnalysis.size()>0){
                tableHeadList =  stepStatusAnalysis[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

        }
        params.SYS_QUERY_NAME = 'stepStatusAnalysisSum'
        stepStatusAnalysisSum = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepList'
        def stepStatusAnalysisStepList = dynamicQueryService.queryForList(params)


        [totalCount:totalCount,tableHeadList:tableHeadList,
         pageSizeList:pageSizeList,pageSize:pageSize,stepStatusAnalysisSum:stepStatusAnalysisSum,
         startno:params.startno?:'',endno:params.endno?:'',step:params.step?:'',stepStatusAnalysis:stepStatusAnalysis,stepStatusAnalysisStepList:stepStatusAnalysisStepList]
    }

    def stepStatusAnalysisStep(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        params.stepName=params.stepName
        params.state=params.state
        def pageSizeList = [10,20,50,100]
        println(params)
        def stepStatusAnalysisStep=[]
        def tableHeadList =  []
        def totalCount=0
        def stepStatusAnalysisStepSumQty=[]
        if(params.state=='WAIT'||params.state=='RUN'||params.state=='REPAIR'||params.state=='OUTSRC'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStep'
            stepStatusAnalysisStep = dynamicQueryService.queryForList(params)
            print(stepStatusAnalysisStep)
            if(stepStatusAnalysisStep.size()>0){
                tableHeadList =  stepStatusAnalysisStep[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepSumQty'
            stepStatusAnalysisStepSumQty = dynamicQueryService.queryForList(params)
        }else if(params.state=='SCRAP'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepScrap'
            stepStatusAnalysisStep = dynamicQueryService.queryForList(params)
            if(stepStatusAnalysisStep.size()>0){
                tableHeadList =  stepStatusAnalysisStep[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepScrapCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepScrapSumQty'
            stepStatusAnalysisStepSumQty = dynamicQueryService.queryForList(params)
        }else if(params.state=='HOLD'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepHold'
            stepStatusAnalysisStep = dynamicQueryService.queryForList(params)
            if(stepStatusAnalysisStep.size()>0){
                tableHeadList =  stepStatusAnalysisStep[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepHoldCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepHoldSumQty'
            stepStatusAnalysisStepSumQty = dynamicQueryService.queryForList(params)
        }

        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepPartNameList'
        def stepStatusAnalysisStepPartNameList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepPartDescList'
        def stepStatusAnalysisStepPartDescList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepGroupList'
        def stepStatusAnalysisStepGroupList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTotalGroupList'
        def stepStatusAnalysisStepTotalGroupList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepDetailCateList'
        def stepStatusAnalysisStepDetailCateList = dynamicQueryService.queryForList(params)


        [totalCount:totalCount,tableHeadList:tableHeadList,
         pageSizeList:pageSizeList,pageSize:pageSize,
         startno:params.startno?:'',endno:params.endno?:'',
         partName:params.partName?:'',stepStatusAnalysisStep:stepStatusAnalysisStep,
         partDesc:params.partDesc?:'',group3:params.group3?:'',totalGroup:params.totalGroup?:'',
         detailCate:params.detailCate?:'',stepName:params.stepName?:'',state:params.state?:'',
         stepStatusAnalysisStepPartNameList:stepStatusAnalysisStepPartNameList,
         stepStatusAnalysisStepPartDescList:stepStatusAnalysisStepPartDescList,
         stepStatusAnalysisStepGroupList:stepStatusAnalysisStepGroupList,
         stepStatusAnalysisStepTotalGroupList:stepStatusAnalysisStepTotalGroupList,
         stepStatusAnalysisStepDetailCateList:stepStatusAnalysisStepDetailCateList,
         stepStatusAnalysisStepSumQty:stepStatusAnalysisStepSumQty
         ]
    }
    def stepStatusAnalysisStepTwo(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent

        def stepStatusAnalysisStepTwo=[]
        def tableHeadList =  []
        def totalCount=0
        def pageSizeList = [10,20,50,100]
        if(params.state1=='WAIT'||params.state1=='RUN'||params.state1=='REPAIR'||params.state1=='OUTSRC'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwo'
            stepStatusAnalysisStepTwo = dynamicQueryService.queryForList(params)

            if(stepStatusAnalysisStepTwo.size()>0){
                tableHeadList =  stepStatusAnalysisStepTwo[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
        }else if(params.state1=='SCRAP'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoScrap'
            stepStatusAnalysisStepTwo = dynamicQueryService.queryForList(params)

            if(stepStatusAnalysisStepTwo.size()>0){
                tableHeadList =  stepStatusAnalysisStepTwo[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoScrapCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
        }else if(params.state1=='HOLD'){
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoHold'
            stepStatusAnalysisStepTwo = dynamicQueryService.queryForList(params)

            if(stepStatusAnalysisStepTwo.size()>0){
                tableHeadList =  stepStatusAnalysisStepTwo[0].keySet()
            }
            params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoHoldCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT
        }


        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoStepNameList'
        def stepStatusAnalysisStepTwoStepNameList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoStepDescList'
        def stepStatusAnalysisStepTwoStepDescList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoLotIdList'
        def stepStatusAnalysisStepTwoLotIdList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoPartNameList'
        def stepStatusAnalysisStepTwoPartNameList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoPartDescList'
        def stepStatusAnalysisStepTwoPartDescList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoGroupList'
        def stepStatusAnalysisStepTwoGroupList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoTotalGroupList'
        def stepStatusAnalysisStepTwoTotalGroupList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoDetailCateList'
        def stepStatusAnalysisStepTwoDetailCateList = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'stepStatusAnalysisStepTwoSum'
        def stepStatusAnalysisStepTwoSum = dynamicQueryService.queryForList(params)

        [totalCount:totalCount,tableHeadList:tableHeadList,
         pageSizeList:pageSizeList,pageSize:pageSize,
         startno:params.startno?:'',endno:params.endno?:'',
         partName1:params.partName1?:'',stepStatusAnalysisStepTwo:stepStatusAnalysisStepTwo,
         partDesc:params.partDesc?:'',group31:params.group31?:'',totalGroup:params.totalGroup?:'',
         detailCate:params.detailCate?:'',stepName1:params.stepName1?:'',state1:params.state1?:'',
         lotId:params.lotId?:'',stepStatusAnalysisStepTwoStepNameList:stepStatusAnalysisStepTwoStepNameList,
         stepStatusAnalysisStepTwoStepDescList:stepStatusAnalysisStepTwoStepDescList,
         stepStatusAnalysisStepTwoPartNameList:stepStatusAnalysisStepTwoPartNameList,
         stepStatusAnalysisStepTwoPartDescList:stepStatusAnalysisStepTwoPartDescList,
         stepStatusAnalysisStepTwoGroupList:stepStatusAnalysisStepTwoGroupList,
         stepStatusAnalysisStepTwoTotalGroupList:stepStatusAnalysisStepTwoTotalGroupList,
         stepStatusAnalysisStepTwoDetailCateList:stepStatusAnalysisStepTwoDetailCateList,
         stepStatusAnalysisStepTwoLotIdList:stepStatusAnalysisStepTwoLotIdList,
         group3:params.group3,partName:params.partName,partDesc:params.partDesc?:'',
         stepName:params.stepName?:'',stepDesc:params.stepDesc?:'',stepStatusAnalysisStepTwoSum:stepStatusAnalysisStepTwoSum

        ]

    }
}
